import Vue from 'vue';
import Main from './message.vue';
let MessageConstructor = Vue.extend(Main);

let instance;
let instances = [];
const Message = function (options) {
    if (Vue.prototype.$isServer) return;
    options = options || {};
    if (typeof options === 'string') {
        options = {
            message: options
        };
    }
    instance = new MessageConstructor({
        data: options
    });
    instance.$mount()
    document.body.appendChild(instance.$el);
    instance.visible = true;
    instances.push(instance);
};

['success', 'warning', 'info', 'error'].forEach(type => {
    Message[type] = options => {
        if (typeof options === 'string') {
            options = {
                message: options
            };
        }
        options.type = type;
        return Message(options);
    };
});


export default Message;
